package com.helmlabs.grouper.core.util;

import org.springframework.security.context.SecurityContextHolder;

import com.helmlabs.grouper.core.exception.NotAuthenticatedException;

public class SecurityUtil {

	public static String getCurrentUsername() throws NotAuthenticatedException {
		if (SecurityContextHolder.getContext() != null) {
			System.out.println("context not null");
			if (SecurityContextHolder.getContext().getAuthentication() != null) {
				System.out.println("authentication not null");
				return (String) SecurityContextHolder.getContext()
						.getAuthentication().getPrincipal();
			}
		}

		throw new NotAuthenticatedException();
	}

}
